#/bin/bash
help()
{
echo "usage:"
echo 'bukload.sh threadNums totalRec seqfield tableName schema '

}
if [ "$1" = "--help" -o "$1" = "-h" -o "$#" != 5 ] ; then
        help
        exit 0
elif [ "$1" = "" ] ; then
        echo 'try: "exp --help or -h" to get usage'
        echo ""
        exit 0
fi
if [[ -f runBuk.sh ]]; then
	#statements
	rm -rf runBuk.sh
	rm -rf whereCluse*
	rm -rf thread_*
fi

threadNums=$1
total=$2
field=$3
tab=$4
schema=$5

comm="java -Dprop=toolkit.properties -jar DBTools-1.0.jar -targetdbtype srdb  "
echo "并发："$threadNums
echo "总数："$total
echo "字段："$field
echo "表名："$tab
# echo $#


for (( i = 1; i <= $threadNums; i++ )); do
	#statements
	if [[ $i = 1  ]]; then
		#statements
		echo "$tab = $field <= $(($i*$total/$threadNums)) " > whereCluse$i.properties
		echo "$comm  -constraints -indexes -dropSchema true -tables $tab -filterProp ./whereCluse$i.properties $schema > thread_$i.log &"  >> runBuk.sh
		echo "sleep 5" >> runBuk.sh

	else
		echo "$tab = $((($i-1)*$total/$threadNums)) < $field and  $field <= $(($i*$total/$threadNums)) " > whereCluse$i.properties
		echo "$comm -dataOnly  -tables $tab -filterProp ./whereCluse$i.properties $schema > thread_$i.log &"  >> runBuk.sh
	fi
	
done
echo `date`
chmod +x runBuk.sh

sh ./runBuk.sh

echo `date`





